/*
 * dwr_ipoque.c
 *
 *  Created on: 21/05/2013
 *      Author: jose
 */

#include <stdlib.h>
#include <assert.h>
#include "dwr_ipoque.h"

ipoque_unique_flow_ipv4_and_6_struct_t * dwr_ipoque_key_create(u32 source_ip, u32 dest_ip,
		u16 source_port, u16 dest_port)
{
	ipoque_unique_flow_ipv4_and_6_struct_t * key =
			(ipoque_unique_flow_ipv4_and_6_struct_t *) calloc(1, sizeof(ipoque_unique_flow_ipv4_and_6_struct_t));
	if (!key)
		return NULL;

	key->ip.ipv4.lower_ip = source_ip;
	key->ip.ipv4.upper_ip = dest_ip;
	key->lower_port = source_port;
	key->upper_port = dest_port;

	return key;
}

void
dwr_key_print(ipoque_unique_flow_ipv4_and_6_struct_t * key)
{
	assert(key);

	printf("\n\tKey: %u.%u.%u.%u", (key->ip.ipv4.lower_ip)&255, (key->ip.ipv4.lower_ip>>8)&255,
			(key->ip.ipv4.lower_ip>>16)&255, (key->ip.ipv4.lower_ip>>24)&255);
	printf(" (%u) ", (u16)(key->lower_port>>8) | (u16)(key->lower_port<<8));
	printf("\t%u.%u.%u.%u", (key->ip.ipv4.upper_ip)&255, (key->ip.ipv4.upper_ip>>8)&255,
			(key->ip.ipv4.upper_ip>>16)&255, (key->ip.ipv4.upper_ip>>24)&255);
	printf(" (%u) ", (u16)(key->upper_port>>8) | (u16)(key->upper_port<<8));

}
